&ACCESS RVP1 &REL 98 &PARAM TEMPLATE = C:\KRC\Roboter\Template\vorgabe &PARAM EDITMASK = * DEF SAKRL( ) ;FOLD INI ;BOOL bContinue ;FOLD BASISTECH INI GLOBAL INTERRUPT DECL 3 WHEN $STOPMESS==TRUE DO IR_STOPM ( ) INTERRUPT ON 3 BAS (#INITMOV,0 ) ;ENDFOLD (BASISTECH INI) ;FOLD USER INI ;Make your modifications here AtHome = 0 AtStart = 0 motionProgramRunning = FALSE bGo = FALSE bAbort = FALSE velocityPct = 20.0 accelerationPct = 20.0 jtVelocityPct = 20.0 jtAccelerationPct = 20.0 extAxisVelocityPct = 20.0 extAxisAccelerationPct = 20.0 GoodMsgCount = 0 NoMsgCount = 0 tstMsgType = 23 MsgType = 23 frameNum = 0 OLD_frameNum = 0 linearApproximation = 75 splineApproximation = 75 sardEStop = FALSE GLOBAL INTERRUPT DECL 5 WHEN sardEStop==TRUE DO HitEStop( ) cmd8InMainLoop = FALSE cmd8InInterruptLoop = FALSE MoveCalled = FALSE InMoveFcn = FALSE GotToEndofGetMessages = FALSE cmd8B4EndOfGetMessages = FALSE cmd8AtEndOfGetMessages = FALSE ;ENDFOLD (USER INI) ;ENDFOLD (INI) ;FOLD Declare Timer-based interrupts for communication ; Interrupt to check for incoming messages every 250ms INTERRUPT DECL 7 WHEN $TIMER[4] >= 95 DO GetMessages() ; Init the timer for the interrupt $TIMER_STOP[4] = TRUE $TIMER[4] = 0 ;ENDFOLD ;FOLD Define Touch Trigger Interrupt ;FLAG to set use of trigger interrupt to true or false ;The actual interrupt definition happens in MoveWithTrigger() ;If set to true robot will stop on trigger intput $FLAG[20]=TRUE ;ENDFOLD ;FOLD PTP HOME Vel= 100 % DEFAULT;%{PE}%R 5.4.24,%MKUKATPBASIS,%CMOVE,%VPTP,%P 1:PTP, 2:HOME, 3:, 5:100, 7:DEFAULT $BWDSTART = FALSE ;Set Base, Tool, and velocities FDAT_ACT=FPDAT LDAT_ACT=LPDAT PDAT_ACT=PPDAT BAS(#CP_PARAMS,0.02 * 100) ; Meters/sec, 2 is max BAS(#ACC_CP, 100) ; BAS(#PTP_PARAMS,100) BAS(#ACC_PTP,100) $H_POS=XHOME PTP $AXIS_ACT ;ENDFOLD ;FOLD Declare sensorname and open a channel bRet = strClear(sensorname[]) sensorname[]="RAC" errint = -100 WHILE errint == -100 errint = EKX_open(sensorname[]) ENDWHILE EKX_handleerror(errint) ;ENDFOLD ;FOLD Build Dataset for messages received ;receive structure - Matches RACData.xml on server & robot rectext[1].s[] = "RAC.RACData.MsgType" rectext[2].s[] = "RAC.RACData.ProgNum" rectext[3].s[] = "RAC.RACData.InspectionIndex" rectext[4].s[] = "RAC.RACData.Position.XPos" rectext[5].s[] = "RAC.RACData.Position.YPos" rectext[6].s[] = "RAC.RACData.Position.ZPos" rectext[7].s[] = "RAC.RACData.Position.APos" rectext[8].s[] = "RAC.RACData.Position.BPos" rectext[9].s[] = "RAC.RACData.Position.CPos" rectext[10].s[] = "RAC.RACData.Closure.Status" rectext[11].s[] = "RAC.RACData.Closure.Turn" rectext[12].s[] = "RAC.RACData.Joints.A1" rectext[13].s[] = "RAC.RACData.Joints.A2" rectext[14].s[] = "RAC.RACData.Joints.A3" rectext[15].s[] = "RAC.RACData.Joints.A4" rectext[16].s[] = "RAC.RACData.Joints.A5" rectext[17].s[] = "RAC.RACData.Joints.A6" rectext[18].s[] = "RAC.RACData.ExternalAxes.Ex1" rectext[19].s[] = "RAC.RACData.ExternalAxes.Ex2" rectext[20].s[] = "RAC.RACData.ExternalAxes.Ex3" rectext[21].s[] = "RAC.RACData.ExternalAxes.Ex4" rectext[22].s[] = "RAC.RACData.ExternalAxes.Ex5" rectext[23].s[] = "RAC.RACData.ExternalAxes.Ex6" rectext[24].s[] = "RAC.RACData.Velocity" rectext[25].s[] = "RAC.RACData.Acceleration" rectext[26].s[] = "RAC.RACData.JtVelocity" rectext[27].s[] = "RAC.RACData.JtAcceleration" rectext[28].s[] = "RAC.RACData.ExAxisVelocity" rectext[29].s[] = "RAC.RACData.ExAxisAcceleration" rectext[30].s[]= "RAC.RACData" ;ENDFOLD ; Fold Initialize Variables bContinue = TRUE MsgCount = 0 Command = #NONE bRet = strClear(ErrorText[]) ErrorText[] = "No errors" ; ENDFOLD ;FOLD Start the Timer based interrupt for reading incoming data INTERRUPT ON 7 $TIMER_STOP[4] = false ; ENDFOLD ; Sent this robot's joint ranges SendJointRanges() ; Since we just moved home, send a status message AtHome = 1 SendStatus() ; ***************** ; MAIN PROGRAM LOOP ; ***************** WHILE bContinue ; "Long" commands are handled in the main loop ; "Short" commands are handled in the message receiver interrupt SWITCH (Command) CASE #NONE CASE #LOAD_PROG Command = #NONE RunMotionProgram() CASE #MOVE_HOME CASE #MOVE_START CASE #MOVE_CART cmd8InMainLoop = TRUE ;Command = #NONE ;MoveToCartesianPosition() ;Command = #NONE CASE #MOVE_JTS ;Command = #NONE ;MoveToJointPose() ;Command = #NONE ENDSWITCH Command = #NONE if tstMsgType == 8 then tstMsgType = 0 MoveWithTrigger(1) endif if tstMsgType == 9 then tstMsgType = 0 MoveWithTrigger(2) endif if tstMsgType == 20 then tstMsgType = 0 MoveWithTrigger(3) endif if tstMsgType == 6 then ;tstMsgType = 0 bContinue = FALSE endif if tstMsgType == 3 then tstMsgType = 0 SendStatus() endif if tstMsgType == 7 then tstMsgType = 0 SendStatus() endif if tstMsgType == 12 then tstMsgType = 0 SendJointRanges() endif if tstMsgType == 13 then tstMsgType = 0 DoForwardKinematics() endif if tstMsgType == 14 then tstMsgType = 0 DoInverseKinematics() endif if tstMsgType == 15 then tstMsgType = 0 GetToolFrame() endif if tstMsgType == 16 then tstMsgType = 0 SetToolFrame() endif if tstMsgType == 17 then tstMsgType = 0 AddFrameToArray() endif if tstMsgType == 18 then tstMsgType = 0 MoveWithTrigger(4) endif if tstMsgType == 19 then tstMsgType = 0 MoveWithTrigger(5) endif if tstMsgType == 25 then tstMsgType = 0 AddJointSetToFrameArray() endif ; Throttle if tstMsgType <> 6 then WAIT SEC 0.1 endif ;Command = #NONE ENDWHILE WAIT SEC 0.3 ;FOLD Close channel EKX_OK = EKX_close(sensorname[]) if EKX_OK == false then halt endif ;ENDFOLD END ;FOLD GetMessages GLOBAL DEF GetMessages() BOOL bNew ; Disable the interrupt to handle without interruption INTERRUPT OFF 7 ; Reset the timer $TIMER_STOP[4] = TRUE $TIMER[4] = 0 intcount = intcount + 1 ; Check for an incoming message - timeout is 12ms (1 IPO) EKX_OK = EKX_waitforsensordata(0,rectext[30].s[], 12) if EKX_OK == false then ; No messages available or a bad or partial message NoMsgCount = NoMsgCount + 1 ELSE ; Get the message Type EKX_OK = EKX_getintegerelement(0, rectext[1].s[], MsgType, bNew) tstMsgType = MsgType if EKX_OK == false then halt endif ; Get the Program number EKX_OK = EKX_getintegerelement(0, rectext[2].s[], ProgNum, bNew) IF((tstMsgType == 18) OR (tstMsgType == 19)) THEN ;If message is dospline or domultilin IF(frameNum <> ProgNum) THEN ;number of total frames must be equal number of frames (to assert all frames were sent in the first place) STOPONERROR() ENDIF ENDIF frameNum = ProgNum if EKX_OK == false then halt endif ; Get the inspection index EKX_OK = EKX_getintegerelement(0, rectext[3].s[], InspIndex, bNew) if EKX_OK == false then halt endif ;get position FOR i=1 TO 6 EKX_OK = EKX_getrealelement(0, rectext[3+i].s[], position[i], bNew) if EKX_OK == false then halt endif ENDFOR ; Get Closure: Status EKX_OK = EKX_getintegerelement(0, rectext[10].s[], closure[1], bNew) if EKX_OK == false then halt endif ; Get the Closure: Turn EKX_OK = EKX_getintegerelement(0, rectext[11].s[], closure[2], bNew) if EKX_OK == false then halt endif ;get joint values FOR j=1 TO 6 EKX_OK = EKX_getrealelement(0, rectext[11+j].s[], joints[j], bNew) if EKX_OK == false then halt endif ENDFOR ;get external axis values FOR k=1 TO 6 EKX_OK = EKX_getrealelement(0, rectext[17+k].s[], extAxes[k], bNew) if EKX_OK == false then halt endif ENDFOR ; Get velocity EKX_OK = EKX_getrealelement(0, rectext[24].s[], velocityPct, bNew) if EKX_OK == false then halt endif ; Get acceleration EKX_OK = EKX_getrealelement(0, rectext[25].s[], accelerationPct, bNew) if EKX_OK == false then halt endif ; Get Axis velocity EKX_OK = EKX_getrealelement(0, rectext[26].s[], jtVelocityPct, bNew) if EKX_OK == false then halt endif ; Get Axis acceleration EKX_OK = EKX_getrealelement(0, rectext[27].s[], jtAccelerationPct, bNew) if EKX_OK == false then halt endif ; Get External Axis velocity EKX_OK = EKX_getrealelement(0, rectext[28].s[], extAxisVelocityPct, bNew) if EKX_OK == false then halt endif ; Get Axis acceleration EKX_OK = EKX_getrealelement(0, rectext[29].s[], extAxisAccelerationPct, bNew) if EKX_OK == false then halt endif ENDIF ; Transform the message into a program command IF Command <> #NONE THEN ; mcc69 Error - cant' handle multiple requests simultaneously - or need to wait...??? ENDIF SWITCH MsgType CASE 1 Command = #LOAD_PROG CASE 2 Command = #EXEC_MOVE CASE 3 ;if motionProgramRunning == TRUE then SendStatus() ;endif Command = #GET_POS CASE 4 Command = #MOVE_HOME CASE 5 Command = #MOVE_START CASE 6 Command = #ABORT_PROG CASE 7 Command = #GET_STATUS CASE 8 Command = #MOVE_CART cmd8InInterruptLoop = TRUE CASE 9 Command = #MOVE_JTS CASE 10 Command = #SET_VEL_ACCEL CASE 11 ;if motionProgramRunning == TRUE then Command = #HIT_E_STOP sardEStop = TRUE ;endif CASE 12 SendJointRanges() CASE 13 DoForwardKinematics() CASE 14 DoInverseKinematics() CASE 15 ;GetToolFrame() Command = #NONE CASE 16 SetToolFrame() Command = #NONE ENDSWITCH IF Command == #MOVE_CART THEN cmd8B4EndOfGetMessages= TRUE ENDIF ; IF A PROGRAM is already loaded and running, then not ; all commands are allowed. Some Commands must be ; handled immediately (GET_POS, GET_STATUS, EXEC_MOVE) SWITCH (Command) CASE #EXEC_MOVE bGo = TRUE Command = #NONE CASE #ABORT_PROG bAbort = TRUE bContinue = FALSE bGo = TRUE Command = #NONE CASE #MOVE_CART CASE #MOVE_JTS CASE #GET_STATUS SendStatus() ;Command = #NONE CASE #GET_POS if motionProgramRunning == TRUE then SendStatus() endif ;Command = #NONE CASE #SET_VEL_ACCEL ;do nothing, values get set from receipt of xml ENDSWITCH GotToEndofGetMessages = TRUE IF Command == #MOVE_CART THEN cmd8AtEndOfGetMessages= TRUE ENDIF ; Enable the interrupt and start the timer INTERRUPT ON 7 $TIMER_STOP[4] = FALSE GoodMsgCount = GoodMsgCount + 1 END ;ENDFOLD ;FOLD WriteStatusInfo DEF WriteStatusInfo() ; Set the atHome, atStart and Error and position fields ; Write the data to the XML structure errint = EKX_WriteReal("RAC.RACData.Position.XPos", $POS_ACT.X) EKX_HandleError(errint) errint = EKX_WriteReal("RAC.RACData.Position.YPos", $POS_ACT.Y) EKX_HandleError(errint) errint = EKX_WriteReal("RAC.RACData.Position.ZPos", $POS_ACT.Z) EKX_HandleError(errint) errint = EKX_WriteReal("RAC.RACData.Position.APos", $POS_ACT.A) EKX_HandleError(errint) errint = EKX_WriteReal("RAC.RACData.Position.BPos", $POS_ACT.B) EKX_HandleError(errint) errint = EKX_WriteReal("RAC.RACData.Position.CPos", $POS_ACT.C) EKX_HandleError(errint) errint = EKX_WriteInteger("RAC.RACData.Closure.Status", $POS_ACT.S) EKX_HandleError(errint) errint = EKX_WriteInteger("RAC.RACData.Closure.Turn", $POS_ACT.T) EKX_HandleError(errint) errint = EKX_WriteReal("RAC.RACData.Joints.A1", $AXIS_ACT.A1) EKX_HandleError(errint) errint = EKX_WriteReal("RAC.RACData.Joints.A2", $AXIS_ACT.A2) EKX_HandleError(errint) errint = EKX_WriteReal("RAC.RACData.Joints.A3", $AXIS_ACT.A3) EKX_HandleError(errint) errint = EKX_WriteReal("RAC.RACData.Joints.A4", $AXIS_ACT.A4) EKX_HandleError(errint) errint = EKX_WriteReal("RAC.RACData.Joints.A5", $AXIS_ACT.A5) EKX_HandleError(errint) errint = EKX_WriteReal("RAC.RACData.Joints.A6", $AXIS_ACT.A6) EKX_HandleError(errint) errint = EKX_WriteReal("RAC.RACData.ExternalAxes.Ex1", $AXIS_ACT.E1) EKX_HandleError(errint) errint = EKX_WriteReal("RAC.RACData.ExternalAxes.Ex2", $AXIS_ACT.E2) EKX_HandleError(errint) errint = EKX_WriteReal("RAC.RACData.ExternalAxes.Ex3", $AXIS_ACT.E3) EKX_HandleError(errint) errint = EKX_WriteReal("RAC.RACData.ExternalAxes.Ex4", $AXIS_ACT.E4) EKX_HandleError(errint) errint = EKX_WriteReal("RAC.RACData.ExternalAxes.Ex5", $AXIS_ACT.E5) EKX_HandleError(errint) errint = EKX_WriteReal("RAC.RACData.ExternalAxes.Ex6", $AXIS_ACT.E6) EKX_HandleError(errint) errint = EKX_WriteReal("RAC.RACData.Velocity", velocityPct) EKX_HandleError(errint) errint = EKX_WriteReal("RAC.RACData.Acceleration", accelerationPct) EKX_HandleError(errint) errint = EKX_WriteReal("RAC.RACData.JtVelocity", jtVelocityPct) EKX_HandleError(errint) errint = EKX_WriteReal("RAC.RACData.JtAcceleration", jtAccelerationPct) EKX_HandleError(errint) errint = EKX_WriteReal("RAC.RACData.ExAxisVelocity", extAxisVelocityPct) EKX_HandleError(errint) errint = EKX_WriteReal("RAC.RACData.ExAxisAcceleration", extAxisAccelerationPct) EKX_HandleError(errint) errint = EKX_WriteInteger("RAC.RACData.AtHome", AtHome) EKX_HandleError(errint) errint = EKX_WriteInteger("RAC.RACData.AtStart", AtStart) EKX_HandleError(errint) errint = EKX_WriteString("RAC.RACData.Error", ErrorText[]) EKX_HandleError(errint) END ;ENDFOLD ;FOLD WriteJointRangeInfo DEF WriteJointRangeInfo() ; Set the atHome, atStart and Error and position fields ; Write the data to the XML structure errint = EKX_WriteReal("RAC.RACData.Position.XPos", $SOFTN_END[1]) EKX_HandleError(errint) errint = EKX_WriteReal("RAC.RACData.Position.YPos", $SOFTP_END[1]) EKX_HandleError(errint) errint = EKX_WriteReal("RAC.RACData.Position.ZPos", $SOFTN_END[2]) EKX_HandleError(errint) errint = EKX_WriteReal("RAC.RACData.Position.APos", $SOFTP_END[2]) EKX_HandleError(errint) errint = EKX_WriteReal("RAC.RACData.Position.BPos", $SOFTN_END[3]) EKX_HandleError(errint) errint = EKX_WriteReal("RAC.RACData.Position.CPos", $SOFTP_END[3]) EKX_HandleError(errint) errint = EKX_WriteInteger("RAC.RACData.Closure.Status", $POS_ACT.S) EKX_HandleError(errint) errint = EKX_WriteInteger("RAC.RACData.Closure.Turn", $POS_ACT.T) EKX_HandleError(errint) errint = EKX_WriteReal("RAC.RACData.Joints.A1", $SOFTN_END[4]) EKX_HandleError(errint) errint = EKX_WriteReal("RAC.RACData.Joints.A2", $SOFTP_END[4]) EKX_HandleError(errint) errint = EKX_WriteReal("RAC.RACData.Joints.A3", $SOFTN_END[5]) EKX_HandleError(errint) errint = EKX_WriteReal("RAC.RACData.Joints.A4", $SOFTP_END[5]) EKX_HandleError(errint) errint = EKX_WriteReal("RAC.RACData.Joints.A5", $SOFTN_END[6]) EKX_HandleError(errint) errint = EKX_WriteReal("RAC.RACData.Joints.A6", $SOFTP_END[6]) EKX_HandleError(errint) errint = EKX_WriteReal("RAC.RACData.ExternalAxes.Ex1", $SOFTN_END[7]) EKX_HandleError(errint) errint = EKX_WriteReal("RAC.RACData.ExternalAxes.Ex2", $SOFTP_END[7]) EKX_HandleError(errint) errint = EKX_WriteReal("RAC.RACData.ExternalAxes.Ex3", $SOFTN_END[8]) EKX_HandleError(errint) errint = EKX_WriteReal("RAC.RACData.ExternalAxes.Ex4", $SOFTP_END[8]) EKX_HandleError(errint) errint = EKX_WriteReal("RAC.RACData.ExternalAxes.Ex5", $SOFTN_END[9]) EKX_HandleError(errint) errint = EKX_WriteReal("RAC.RACData.ExternalAxes.Ex6", $SOFTP_END[9]) EKX_HandleError(errint) errint = EKX_WriteReal("RAC.RACData.Velocity", $SOFTN_END[10]) EKX_HandleError(errint) errint = EKX_WriteReal("RAC.RACData.Acceleration", $SOFTP_END[10]) EKX_HandleError(errint) errint = EKX_WriteReal("RAC.RACData.JtVelocity", $SOFTN_END[11]) EKX_HandleError(errint) errint = EKX_WriteReal("RAC.RACData.JtAcceleration", $SOFTP_END[11]) EKX_HandleError(errint) errint = EKX_WriteReal("RAC.RACData.ExAxisVelocity", $SOFTN_END[12]) EKX_HandleError(errint) errint = EKX_WriteReal("RAC.RACData.ExAxisAcceleration", $SOFTP_END[12]) EKX_HandleError(errint) errint = EKX_WriteInteger("RAC.RACData.AtHome", AtHome) EKX_HandleError(errint) errint = EKX_WriteInteger("RAC.RACData.AtStart", AtStart) EKX_HandleError(errint) errint = EKX_WriteString("RAC.RACData.Error", ErrorText[]) EKX_HandleError(errint) ;inSendRanges = true END ;ENDFOLD ;FOLD WriteTOOLFrameInfo DEF WriteTOOLFrameInfo() ; Write the data to the XML structure errint = EKX_WriteReal("RAC.RACData.Position.XPos", TOOL_DATA[16].X) EKX_HandleError(errint) errint = EKX_WriteReal("RAC.RACData.Position.YPos", TOOL_DATA[16].Y) EKX_HandleError(errint) errint = EKX_WriteReal("RAC.RACData.Position.ZPos", TOOL_DATA[16].Z) EKX_HandleError(errint) errint = EKX_WriteReal("RAC.RACData.Position.APos", TOOL_DATA[16].A) EKX_HandleError(errint) errint = EKX_WriteReal("RAC.RACData.Position.BPos", TOOL_DATA[16].B) EKX_HandleError(errint) errint = EKX_WriteReal("RAC.RACData.Position.CPos", TOOL_DATA[16].C) EKX_HandleError(errint) errint = EKX_WriteInteger("RAC.RACData.Closure.Status", $POS_ACT.S) EKX_HandleError(errint) errint = EKX_WriteInteger("RAC.RACData.Closure.Turn", $POS_ACT.T) EKX_HandleError(errint) errint = EKX_WriteReal("RAC.RACData.Joints.A1", $AXIS_ACT.A1) EKX_HandleError(errint) errint = EKX_WriteReal("RAC.RACData.Joints.A2", $AXIS_ACT.A2) EKX_HandleError(errint) errint = EKX_WriteReal("RAC.RACData.Joints.A3", $AXIS_ACT.A3) EKX_HandleError(errint) errint = EKX_WriteReal("RAC.RACData.Joints.A4", $AXIS_ACT.A4) EKX_HandleError(errint) errint = EKX_WriteReal("RAC.RACData.Joints.A5", $AXIS_ACT.A5) EKX_HandleError(errint) errint = EKX_WriteReal("RAC.RACData.Joints.A6", $AXIS_ACT.A6) EKX_HandleError(errint) errint = EKX_WriteReal("RAC.RACData.ExternalAxes.Ex1", $AXIS_ACT.E1) EKX_HandleError(errint) errint = EKX_WriteReal("RAC.RACData.ExternalAxes.Ex2", $AXIS_ACT.E2) EKX_HandleError(errint) errint = EKX_WriteReal("RAC.RACData.ExternalAxes.Ex3", $AXIS_ACT.E3) EKX_HandleError(errint) errint = EKX_WriteReal("RAC.RACData.ExternalAxes.Ex4", $AXIS_ACT.E4) EKX_HandleError(errint) errint = EKX_WriteReal("RAC.RACData.ExternalAxes.Ex5", $AXIS_ACT.E5) EKX_HandleError(errint) errint = EKX_WriteReal("RAC.RACData.ExternalAxes.Ex6", $AXIS_ACT.E6) EKX_HandleError(errint) errint = EKX_WriteReal("RAC.RACData.Velocity", velocityPct) EKX_HandleError(errint) errint = EKX_WriteReal("RAC.RACData.Acceleration", accelerationPct) EKX_HandleError(errint) errint = EKX_WriteReal("RAC.RACData.JtVelocity", jtVelocityPct) EKX_HandleError(errint) errint = EKX_WriteReal("RAC.RACData.JtAcceleration", jtAccelerationPct) EKX_HandleError(errint) errint = EKX_WriteReal("RAC.RACData.ExAxisVelocity", extAxisVelocityPct) EKX_HandleError(errint) errint = EKX_WriteReal("RAC.RACData.ExAxisAcceleration", extAxisAccelerationPct) EKX_HandleError(errint) errint = EKX_WriteInteger("RAC.RACData.AtHome", AtHome) EKX_HandleError(errint) errint = EKX_WriteInteger("RAC.RACData.AtStart", AtStart) EKX_HandleError(errint) errint = EKX_WriteString("RAC.RACData.Error", ErrorText[]) EKX_HandleError(errint) ;inSendRanges = true END ;ENDFOLD ;FOLD WriteKinematicInfo DEF WriteKinematicInfo() ; Set the atHome, atStart and Error and position fields ; Write the data to the XML structure errint = EKX_WriteReal("RAC.RACData.Position.XPos", PPOS.X) EKX_HandleError(errint) errint = EKX_WriteReal("RAC.RACData.Position.YPos", PPOS.Y) EKX_HandleError(errint) errint = EKX_WriteReal("RAC.RACData.Position.ZPos", PPOS.Z) EKX_HandleError(errint) errint = EKX_WriteReal("RAC.RACData.Position.APos", PPOS.A) EKX_HandleError(errint) errint = EKX_WriteReal("RAC.RACData.Position.BPos", PPOS.B) EKX_HandleError(errint) errint = EKX_WriteReal("RAC.RACData.Position.CPos", PPOS.C) EKX_HandleError(errint) errint = EKX_WriteInteger("RAC.RACData.Closure.Status", PPOS.S) EKX_HandleError(errint) errint = EKX_WriteInteger("RAC.RACData.Closure.Turn", PPOS.T) EKX_HandleError(errint) errint = EKX_WriteReal("RAC.RACData.Joints.A1", PAXIS.A1) EKX_HandleError(errint) errint = EKX_WriteReal("RAC.RACData.Joints.A2", PAXIS.A2) EKX_HandleError(errint) errint = EKX_WriteReal("RAC.RACData.Joints.A3", PAXIS.A3) EKX_HandleError(errint) errint = EKX_WriteReal("RAC.RACData.Joints.A4", PAXIS.A4) EKX_HandleError(errint) errint = EKX_WriteReal("RAC.RACData.Joints.A5", PAXIS.A5) EKX_HandleError(errint) errint = EKX_WriteReal("RAC.RACData.Joints.A6", PAXIS.A6) EKX_HandleError(errint) errint = EKX_WriteReal("RAC.RACData.ExternalAxes.Ex1", PEXTAXIS.E1) EKX_HandleError(errint) errint = EKX_WriteReal("RAC.RACData.ExternalAxes.Ex2", PEXTAXIS.E2) EKX_HandleError(errint) errint = EKX_WriteReal("RAC.RACData.ExternalAxes.Ex3", PEXTAXIS.E3) EKX_HandleError(errint) errint = EKX_WriteReal("RAC.RACData.ExternalAxes.Ex4", PEXTAXIS.E4) EKX_HandleError(errint) errint = EKX_WriteReal("RAC.RACData.ExternalAxes.Ex5", PEXTAXIS.E5) EKX_HandleError(errint) errint = EKX_WriteReal("RAC.RACData.ExternalAxes.Ex6", PEXTAXIS.E6) EKX_HandleError(errint) errint = EKX_WriteReal("RAC.RACData.Velocity", velocityPct) EKX_HandleError(errint) errint = EKX_WriteReal("RAC.RACData.Acceleration", accelerationPct) EKX_HandleError(errint) errint = EKX_WriteReal("RAC.RACData.JtVelocity", jtVelocityPct) EKX_HandleError(errint) errint = EKX_WriteReal("RAC.RACData.JtAcceleration", jtAccelerationPct) EKX_HandleError(errint) errint = EKX_WriteReal("RAC.RACData.ExAxisVelocity", extAxisVelocityPct) EKX_HandleError(errint) errint = EKX_WriteReal("RAC.RACData.ExAxisAcceleration", extAxisAccelerationPct) EKX_HandleError(errint) errint = EKX_WriteInteger("RAC.RACData.AtHome", AtHome) EKX_HandleError(errint) errint = EKX_WriteInteger("RAC.RACData.AtStart", AtStart) EKX_HandleError(errint) errint = EKX_WriteString("RAC.RACData.Error", ErrorText[]) EKX_HandleError(errint) END ;ENDFOLD ;FOLD SendStatus GLOBAL DEF SendStatus() ; Set the message type ; Write the data to the XML structure errint = EKX_WriteInteger("RAC.RACData.MsgType", 3) EKX_HAndleError(errint) WriteStatusInfo() SendMsg() ;$TIMER[5] = 0 END ;ENDFOLD ;FOLD SendReady GLOBAL DEF SendReady() ; Set the message type ; Write the data to the XML structure errint = EKX_WriteInteger("RAC.RACData.MsgType", 1) EKX_HAndleError(errint) WriteStatusInfo() SendMsg() END ;ENDFOLD ;FOLD SendJointRanges GLOBAL DEF SendJointRanges() ; Set the message type ; Write the data to the XML structure errint = EKX_WriteInteger("RAC.RACData.MsgType", 12) EKX_HAndleError(errint) WriteJointRangeInfo() SendMsg() END ;ENDFOLD ;FOLD DoForwardKinematics GLOBAL DEF DoForwardKinematics() ; Set the message type ; Write the data to the XML structure errint = EKX_WriteInteger("RAC.RACData.MsgType", 13) EKX_HAndleError(errint) ;Make sure frame settings are correct for FORWARD calculation FDAT_ACT=FPDAT PDAT_ACT=PPDAT LDAT_ACT=LPDAT ;Set joint values for FORWARD() kineamtics calulation ;-->remark: ext axis are not set on purpose ;-->PAXIS is a POs variable PAXIS.A1=joints[1] PAXIS.A2=joints[2] PAXIS.A3=joints[3] PAXIS.A4=joints[4] PAXIS.A5=joints[5] PAXIS.A6=joints[6] PAXIS.E1 = $AXIS_ACT.E1 ;Do Forward() twice, because it sometimes fails on the first try errint=0 ;Try to do forward calculations (twice because it fails sometimes PPOS = FORWARD(PAXIS, errint) IF(errint <> 0 ) THEN PPOS = FORWARD(PAXIS, errint) ;Try it a second time IF(errint <> 0 ) THEN BRAKE F ;Stop Motion HALT ;Stop the program, because error occured ENDIF ENDIF ;Send calculated position back to SA WriteKinematicInfo() SendMsg() END ;ENDFOLD ;FOLD DoInverseKinematics -- FROM CURRENT JOINT POSITION GLOBAL DEF DoInverseKinematics() ; Set the message type ; Write the data to the XML structure ; errint = EKX_WriteInteger("RAC.RACData.MsgType", 14) ; EKX_HAndleError(errint) ; PPOS.X=position[1] ; PPOS.Y=position[2] ; PPOS.Z=position[3] ; PPOS.A=position[4] ; PPOS.B=position[5] ; PPOS.C=position[6] ; PPOS.S=closure[1] ; PPOS.T=closure[2] ; PAXIS = INVERSE (PPOS, $AXIS_ACT, errint) ; always from current frame, $AXIS_ACT ; WriteKinematicInfo() ; SendMsg() END ;ENDFOLD ;FOLD Move Any Command --> With Trigger Intrrupt GLOBAL DEF MoveWithTrigger(moveCommandNum: IN) DECL INT moveCommandNum ;Disable Communication and reset timer INTERRUPT OFF 7 $TIMER_STOP[4]=TRUE $TIMER[4]=50 ;Define the trigger interrupt INTERRUPT DECL 6 WHEN $meas_pulse[1]==false DO OnTriggerInterrupt() ;Enable Touch Trigger only for one frame at a time motions INTERRUPT ON 6 SWITCH (moveCommandNum) CASE 1 MoveToCartesianPosition() CASE 2 MoveToJointPose() ENDSWITCH ;Disable Touch Trigger INTERRUPT OFF 6 SWITCH (moveCommandNum) CASE 3 MoveExternalAxes() CASE 4 DoSpline() CASE 5 DoMultiLin() ENDSWITCH ;Reset framenums for security check OLD_frameNum = 0 frameNum = 0 ;Enable Communication INTERRUPT ON 7 $TIMER_STOP[4]=FALSE SendStatus() END ;ENDFOLD ;FOLD SetToolFrame -- W.R.T. Flange Frame GLOBAL DEF SetToolFrame() ; advance run... TOOL_DATA[16].X=position[1] TOOL_DATA[16].Y=position[2] TOOL_DATA[16].Z=position[3] TOOL_DATA[16].A=position[4] TOOL_DATA[16].B=position[5] TOOL_DATA[16].C=position[6] END ;ENDFOLD ;FOLD GetToolFrame -- W.R.T. Flange Frame GLOBAL DEF GetToolFrame() ; Set the message type ; Write the data to the XML structure errint = EKX_WriteInteger("RAC.RACData.MsgType", 15) EKX_HAndleError(errint) WriteToolFrameInfo() SendMsg() END ;ENDFOLD ;FOLD PTP Move to commanded Cartesian Position DEF MoveToCartesianPosition() Command = #NONE MoveCalled = TRUE IF motionProgramRunning == FALSE THEN bGo = TRUE bAbort = FALSE sardEStop = FALSE motionProgramRunning = TRUE MoveToFrame() ELSE bRet = strClear(ErrorText[]) ENDIF END ;ENDFOLD ;FOLD PTP Move to commanded Joint Pose DEF MoveToJointPose() Command = #NONE MoveCalled = TRUE IF motionProgramRunning == FALSE THEN bGo = TRUE bAbort = FALSE sardEStop = FALSE motionProgramRunning = TRUE MoveToJointSet() ELSE bRet = strClear(ErrorText[]) ENDIF END ;ENDFOLD ;FOLD PTP Move External Axes DEF MoveExternalAxes() Command = #NONE MoveCalled = TRUE IF motionProgramRunning == FALSE THEN bGo = TRUE bAbort = FALSE sardEStop = FALSE motionProgramRunning = TRUE MoveToExternalAxisSet() ELSE bRet = strClear(ErrorText[]) ;ErrorText[] = "Motion already running" ;SendStatus() ENDIF END ;ENDFOLD ;FOLD AddFrameToArray DEF AddFrameToArray() ;Initial check to prevent lost frames and doble frames ; If frame is sent twice frameNum will be equal OLD_frameNum and this check will fail ; If a frame is lost frameNum will be equal to OLD_frameNum +2 and this check will also fail ; So security should be gurateed IF(OLD_frameNum + 1 <> frameNum) THEN STOPONERROR() ENDIF ;Make sure frame settings are correct FDAT_ACT=FPDAT PDAT_ACT=PPDAT LDAT_ACT=LPDAT ARRAYPOS[frameNum].X=position[1] ARRAYPOS[frameNum].Y=position[2] ARRAYPOS[frameNum].Z=position[3] ARRAYPOS[frameNum].A=position[4] ARRAYPOS[frameNum].B=position[5] ARRAYPOS[frameNum].C=position[6] ARRAYPOS[frameNum].S=closure[1] ARRAYPOS[frameNum].T=closure[2] ARRAYPOS[frameNum].E1 = $AXIS_ACT.E1 ;always use current rail position ;Assign Old FrameNum OLD_frameNum = frameNum ;send frame was added to robot driver ;11/16/2017 Santiago, frame syc XIT-707 SendFrameWasAdded() END ;ENDFOLD ;FOLD AddJointSetToFrameArray GLOBAL DEF AddJointSetToFrameArray() ;Initial check to prevent lost frames and doble frames ; If frame is sent twice frameNum will be equal OLD_frameNum and this check will fail ; If a frame is lost frameNum will be equal to OLD_frameNum +2 and this check will also fail ; So security should be gurateed IF(OLD_frameNum + 1 <> frameNum) THEN STOPONERROR() ENDIF ;Make sure frame settings are correct for FORWARD calculation FDAT_ACT=FPDAT PDAT_ACT=PPDAT LDAT_ACT=LPDAT ;Set joint values for FORWARD() kineamtics calulation ;-->PAXIS is a E6AXIS variable PAXIS.A1=joints[1] PAXIS.A2=joints[2] PAXIS.A3=joints[3] PAXIS.A4=joints[4] PAXIS.A5=joints[5] PAXIS.A6=joints[6] PAXIS.E1=$AXIS_ACT.E1 ;Do Forward() twice, because it sometimes fails on the first try errint=0 ;Try to do forward calculations (twice because it fails sometimes PPOS = FORWARD(PAXIS, errint) IF(errint <> 0 ) THEN PPOS = FORWARD(PAXIS, errint) ;Try it a second time IF(errint <> 0 ) THEN STOPONERROR() ENDIF ENDIF ;Add calculated position to frame array ARRAYPOS[frameNum].X=PPOS.X ARRAYPOS[frameNum].Y=PPOS.Y ARRAYPOS[frameNum].Z=PPOS.Z ARRAYPOS[frameNum].A=PPOS.A ARRAYPOS[frameNum].B=PPOS.B ARRAYPOS[frameNum].C=PPOS.C ARRAYPOS[frameNum].S=PPOS.S ARRAYPOS[frameNum].T=PPOS.T ARRAYPOS[frameNum].E1=PPOS.E1 ;Assign Old FrameNum OLD_frameNum = frameNum ;send frame was added to robot driver ;11/16/2017 Santiago, frame syc XIT-707 SendFrameWasAdded() END ;ENDFOLD ;FOLD OnTriggerInterrupt GLOBAL DEF OnTriggerInterrupt( ) ;Disable Touch Trigger Interrupt to prevent contact bouncing INTERRUPT OFF 6 ;Break motion fast BRAKE F ;Base, Tool, Vel, Acc settings FDAT_ACT=FPDAT LDAT_ACT=LPDAT $VEL.CP = DEF_VEL_CP ;Max default value from config.dat $ACC.CP = DEF_ACC_CP ;Max default value from config.dat ;Linear retract move LIN PRETRACT ;Send Position reached SendMotionComplete() ;Resume Program at interrupt trigger level RESUME END ;ENDFOLD ;FOLD MoveToJointSet DEF MoveToJointSet( ) ;SAKRL Internal INTERRUPT ON 5 ; our 'estop' in the SA Robot interface InMoveFcn = TRUE ;Set Approximation to 0 $ADVANCE=0 ;Base, Tool, Vel, Acc settings FDAT_ACT=FPDAT PDAT_ACT=PPDAT BAS(#PTP_PARAMS,jtVelocityPct) BAS(#ACC_PTP,jtAccelerationPct) ;Current Robot Position. Used for retract position if TriggerInterrupt is enabled PRETRACT = $POS_ACT ;Assign Joints PAXIS.A1=joints[1] PAXIS.A2=joints[2] PAXIS.A3=joints[3] PAXIS.A4=joints[4] PAXIS.A5=joints[5] PAXIS.A6=joints[6] PAXIS.E1 = $AXIS_ACT.E1 PTP PAXIS ;Inform SA that the motion is complete SendStatus() SendMotionComplete() END ;ENDFOLD ;FOLD MoveToFrame DEF MoveToFrame( ) ;SAKRL Internal INTERRUPT ON 5 ; our 'estop' in the SA Robot interface InMoveFcn = TRUE ;Set Approximation to 0 $ADVANCE=0 ;Base, Tool, Vel, Acc settings FDAT_ACT=FPDAT LDAT_ACT=LPDAT BAS(#CP_PARAMS, 0.02 * velocityPct) ; max 2 m/s, velocityPct in % BAS(#ACC_CP, accelerationPct) ; accelertationPct in % ;Current Robot Position. Used for retract position if TriggerInterrupt is enabled PRETRACT = $POS_ACT ;Assign Position PPOS.X=position[1] PPOS.Y=position[2] PPOS.Z=position[3] PPOS.A=position[4] PPOS.B=position[5] PPOS.C=position[6] PAXIS.E1=$AXIS_ACT.E1 PPOS.S=closure[1] PPOS.T=closure[2] LIN PPOS ;Inform SA that the motion is complete SendStatus() SendMotionComplete() END ;ENDFOLD ;FOLD MoveToExternalAxisSet DEF MoveToExternalAxisSet( ) ;SAKRL Internal INTERRUPT ON 5 ; our 'estop' in the SA Robot interface InMoveFcn = TRUE ;Set Approximation to 0 $ADVANCE=0 ;Base, Tool, Vel, Acc settings FDAT_ACT=FPDAT PDAT_ACT=PPDAT BAS(#PTP_PARAMS,extAxisVelocityPct) BAS(#ACC_PTP,extAxisAccelerationPct) ;Current Robot Position. Used for retract position if TriggerInterrupt is enabled PRETRACT = $POS_ACT ;Fix Joints for ext axis movements PEXTAXIS.A1 = $AXIS_ACT.A1; PEXTAXIS.A2 = $AXIS_ACT.A2; PEXTAXIS.A3 = $AXIS_ACT.A3; PEXTAXIS.A4 = $AXIS_ACT.A4; PEXTAXIS.A5 = $AXIS_ACT.A5; PEXTAXIS.A6 = $AXIS_ACT.A6; ;Set external axis move data PEXTAXIS.E1 = extAxes[1] PEXTAXIS.E2 = extAxes[2] PEXTAXIS.E3 = extAxes[3] PEXTAXIS.E4 = extAxes[4] PEXTAXIS.E5 = extAxes[5] PEXTAXIS.E6 = extAxes[6] PTP PEXTAXIS ;Inform SA that the motion is complete SendStatus() SendMotionComplete() END ;ENDFOLD ;FOLD DoMultiLIN GLOBAL DEF DoMultiLIN() DECL INT COUNT $ADVANCE = 3 ;Set Base, Tool, and velocities FDAT_ACT=FPDAT LDAT_ACT=LPDAT BAS(#CP_PARAMS,0.02 * velocityPct) ; Meters/sec, 2 is max BAS(#ACC_CP, accelerationPct) ; Meters/sec^2, 25 is max ;Set small approximation distance and advance run ;Those must be set after BAS commands, becuase BAS set APO dist to PDAT_ACT.APO_DIST $APO.CDIS = linearApproximation $APO.CPTP = splineApproximation ;Start motion FOR COUNT=1 TO frameNum CONTINUE ARRAYPOS[COUNT].E1 = $AXIS_ACT.E1 CONTINUE LIN ARRAYPOS[COUNT] C_DIS ENDFOR ;Reset Advance run $ADVANCE=0 ;Reset framenums for security check OLD_frameNum = 0 frameNum = 0 ;This is needed because the message interrupt is undefined for motions ( because of the trigger interrupt ) ;If the motion is too long SA will have internal timout conflicts -> SendStatus() go get SA up to date SendStatus() ;Send Motion complete SendMotionComplete() END ;ENDFOLD ;FOLD DoSpline GLOBAL DEF DoSpline() DECL INT COUNT ;Three steps are calculated in advance $ADVANCE = 3 ;Set Base, Tool, and velocities FDAT_ACT=FPDAT PDAT_ACT=PPDAT BAS(#PTP_PARAMS,jtVelocityPct) BAS(#ACC_PTP,jtAccelerationPct) ;Set approximation distance and advance run ;Those must be set after BAS commands, becuase BAS set APO dist to PDAT_ACT.APO_DIST $APO.CDIS = linearApproximation $APO.CPTP = splineApproximation ;Start motion FOR COUNT=1 TO frameNum ;Used PTP istead of spline (much faster) CONTINUE ARRAYPOS[COUNT].E1 = $AXIS_ACT.E1 CONTINUE PTP ARRAYPOS[COUNT] C_PTP ENDFOR ;Reset Advance run $ADVANCE=0 ;Reset framenums for security check OLD_frameNum = 0 frameNum = 0 ;This is needed because the message interrupt is undefined for motions ( because of the trigger interrupt ) ;If the motion is too long SA will have internal timout conflicts -> SendStatus() go get SA up to date SendStatus() ;Send Motion complete SendMotionComplete() END ;ENDFOLD ;FOLD SendMotionComplete GLOBAL DEF SendMotionComplete() AtHome = 0 AtStart = 0 motionProgramRunning = FALSE ; Set the message type and current inspection point ; Write the data to the XML structure errint = EKX_WriteInteger("RAC.RACData.MsgType", 2) EKX_HAndleError(errint) WriteStatusInfo() SendMsg() END ;ENDFOLD ;FOLD SendFrameWasAdded ;11/16/2017 Santiago, frame syc XIT-707 GLOBAL DEF SendFrameWasAdded() AtHome = 0 AtStart = 0 motionProgramRunning = FALSE ; Set the message type and current inspection point ; Write the data to the XML structure errint = EKX_WriteInteger("RAC.RACData.MsgType", 26) EKX_HAndleError(errint) WriteStatusInfo() SendMsg() END ;ENDFOLD ;FOLD SendProgramComplete GLOBAL DEF SendProgramComplete() ; Send the current status, because this info should be updated AtHome = 0 AtStart = 1 motionProgramRunning = FALSE ; Set the message type ; Write the data to the XML structure errint = EKX_WriteInteger("RAC.RACData.MsgType", 4) EKX_HAndleError(errint) WriteStatusInfo() SendMsg() END ;ENDFOLD ;FOLD SendMsg GLOBAL DEF SendMsg() ;FOLD Increase message counter MsgCount = MsgCount + 1 errint = EKX_WriteInteger("RAC.RACData.MsgCount", MsgCount) EKX_HandleError(errint) ;ENDFOLD errint = EKX_Send("RAC") EKX_HandleError(errint) END ;ENDFOLD ;FOLD RunMotionProgram DEF RunMotionProgram() IF motionProgramRunning == FALSE THEN bGo = TRUE bAbort = FALSE motionProgramRunning = TRUE SWITCH ProgNum CASE 1 ;Insp1() CASE 2 ;Insp2() ENDSWITCH ELSE bRet = strClear(ErrorText[]) ErrorText[] = "Program already running" SendStatus() ENDIF END ;ENDFOLD ;FOLD ProgramIsReady GLOBAL DEF ProgramIsReady() AtHome = 0 AtStart = 1 bGo = FALSE SendReady() END ;ENDFOLD ;FOLD AtInspPoint GLOBAL DEF AtInspPoint(PointNum : IN) INT PointNum CurInspPoint = PointNum SendMotionComplete() END ;ENDFOLD ;FOLD ProgramComplete GLOBAL DEF ProgramComplete() SendProgramComplete() END ;ENDFOLD ;FOLD HitEStop GLOBAL DEF HitEStop( ) INTERRUPT OFF 5 BRAKE ; soft stop without the F RESUME ; back to SAKRL END ;ENDFOLD ;FOLD StopOnError() GLOBAL DEF STOPONERROR() BRAKE F ; Hard Stop ;EKX_OK = EKX_close(sensorname[]) ;Stop Connecction HALT ; Halt Robot END ;ENDFOLD